package com.bright.cwduijie.duijie.service.impl;

import com.bright.cwduijie.duijie.enums.DataApi;
import com.bright.cwduijie.duijie.enums.OpType;
import com.bright.cwduijie.duijie.enums.SJJHBZ;
import com.bright.cwduijie.duijie.pojo.bo.ApiDataCollection;
import com.bright.cwduijie.duijie.pojo.dto.CheckResultDto;
import com.bright.cwduijie.duijie.pojo.po.FixedAssets;
import com.bright.cwduijie.duijie.pojo.query.DuijieQuery;
import com.bright.cwduijie.duijie.repository.FixedAssetsRepository;
import com.bright.cwduijie.duijie.service.AbstractApiService;
import com.bright.cwduijie.duijie.service.AbstractPerThousandApiService;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.function.Function;


@Component
@RequiredArgsConstructor
@Slf4j
public class ApiFixedAssetsServiceImpl extends AbstractPerThousandApiService<FixedAssets> {

    private final FixedAssetsRepository fixedAssetsRepository;

    @Override
    public JpaSpecificationExecutor getJpaSpecificationExecutor() {
        return fixedAssetsRepository;
    }

    @Override
    public DataApi getDataApi() {
        return DataApi.FIXED_ASSETS;
    }

    @Override
    public Function<FixedAssets, Integer> getIdFunc() {
        return FixedAssets::getId;
    }

    @Override
    public Function<FixedAssets, String> getDataKeyFunc() {
        return FixedAssets::getDATA_KEY;
    }

    @Override
    public Function<ApiDataCollection, List<FixedAssets>> getDataFunc() {
        return ApiDataCollection::getFixedAssets;
    }

    @Override
    protected DataApi getDeleteDataApi() {
        return DataApi.DELETE_FIXED_ASSETS;
    }


    @Override
    protected void getData(ApiDataCollection apiDataCollection, DuijieQuery duijieQuery) {
//        List<FixedAssets> fixedAssets = fixedAssetsRepository.getAllByZtDataKeyAndSjjhbz(duijieQuery.getZtDataKey(), SJJHBZ.WAITING.getValue(), OpType.ADD_OR_EDIT.getValue());
//        fixedAssets.addAll(fixedAssetsRepository.getAllByZtDataKeyAndSjjhbz(duijieQuery.getZtDataKey(), SJJHBZ.ERROR.getValue(), OpType.ADD_OR_EDIT.getValue()));
        apiDataCollection.setFixedAssets(getNeedDuijieData(duijieQuery));
    }

//    @Override
//    protected List<FixedAssets> getNeedDeleteData(DuijieQuery duijieQuery) {
//        List<FixedAssets> fixedAssets = fixedAssetsRepository.getAllByZtDataKeyAndSjjhbz(duijieQuery.getZtDataKey(), SJJHBZ.WAITING.getValue(), OpType.DEL.getValue());
//        fixedAssets.addAll(fixedAssetsRepository.getAllByZtDataKeyAndSjjhbz(duijieQuery.getZtDataKey(), SJJHBZ.ERROR.getValue(), OpType.DEL.getValue()));
//        return fixedAssets;
//    }

    public List<Integer> getIdsByDataKeys(List<String> dataKeys) {
        return fixedAssetsRepository.getIdListByDataKeys(dataKeys);
    }

}
